// src/api/student.js
import request from '@/utils/request'

// ======================== Dashboard统计相关 ========================

/**
 * 获取题目查重统计
 * @returns {Promise}
 */
export function getTitleCheckStats() {
  return request({
    url: '/student/dashboard/title-check-stats',
    method: 'get'
  })
}

/**
 * 获取信息提取统计
 * @returns {Promise}
 */
export function getExtractionStats() {
  return request({
    url: '/student/dashboard/extraction-stats',
    method: 'get'
  })
}

/**
 * 获取最近查重记录
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getRecentRecords(params) {
  return request({
    url: '/student/dashboard/recent-records',
    method: 'get',
    params: {
      limit: params.limit || 5
    }
  })
}

// ======================== 题目查重相关 ========================

/**
 * 提交题目查重
 * @param {Object} data 查重数据
 * @returns {Promise}
 */
export function submitTitleCheck(data) {
  return request({
    url: '/student/title-check',
    method: 'post',
    data,
    timeout: 30000
  })
}

/**
 * 获取题目查重历史
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getTitleCheckHistory(params) {
  return request({
    url: '/student/title-check/history',
    method: 'get',
    params: {
      page: params.page || 1,
      size: params.size || 10
    }
  })
}

/**
 * 获取查重结果详情
 * @param {string} taskId 任务ID
 * @returns {Promise}
 */
export function getTitleCheckResult(taskId) {
  return request({
    url: `/student/title-check/${taskId}`,
    method: 'get'
  })
}

// ======================== 论文查重相关 ========================

/**
 * 上传PDF文件
 * @param {FormData} formData 文件数据
 * @returns {Promise}
 */
export function uploadPaper(formData) {
  return request({
    url: '/student/paper/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    timeout: 30000
  })
}

/**
 * 提交内容查重
 * @param {Object} data 查重配置
 * @returns {Promise}
 */
export function submitPaperCheck(data) {
  return request({
    url: '/student/paper/check',
    method: 'post',
    data
  })
}

/**
 * 获取查重结果
 * @param {string} taskId 任务ID
 * @returns {Promise}
 */
export function getCheckResult(taskId) {
  return request({
    url: `/student/paper/check/${taskId}`,
    method: 'get'
  })
}

/**
 * 获取论文查重历史
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getPaperCheckHistory(params) {
  return request({
    url: '/student/paper/history',
    method: 'get',
    params: {
      page: params.page || 1,
      size: params.size || 10
    }
  })
}

// ======================== 信息提取相关 ========================

/**
 * 提交信息提取任务
 * @param {Object} data 提取配置
 * @returns {Promise}
 */
export function submitInfoExtraction(data) {
  return request({
    url: '/student/paper/extract-info',
    method: 'post',
    data,
    timeout: 60000
  })
}

/**
 * 单独提取某项信息
 * @param {Object} data 提取配置
 * @returns {Promise}
 */
export function extractSingleItem(data) {
  return request({
    url: '/student/paper/extract-single',
    method: 'post',
    data
  })
}

/**
 * 批量导出信息
 * @param {Object} data 导出配置
 * @returns {Promise}
 */
export function exportPaperInfoBatch(data) {
  return request({
    url: '/student/paper/export-batch',
    method: 'post',
    data
  })
}

/**
 * 获取导出结果
 * @param {string} exportId 导出任务ID
 * @returns {Promise}
 */
export function getExportResult(exportId) {
  return request({
    url: `/student/paper/export/${exportId}`,
    method: 'get'
  })
}